using DG.Tweening;
using System.Collections;
using System.Linq;
using UnityEngine;

public class UmbrellaSkill3Area : TriggerSkillCollider
{
    public GameObject spriteObj;

    public override void Initialize(SkillData data, float radius, bool isShow = true)
    {
        base.Initialize(data, radius, isShow);

        transform.position = owner.transform.position;
        transform.localScale = new Vector3(radius * 0.2f, radius * 0.2f, 1);
        StartCoroutine(ThisSkill(data));
    }

    private IEnumerator ThisSkill(SkillData info)
    {
        spriteObj.SetActive(true);
        spriteObj.transform.position = transform.position + new Vector3(0, 5, 0);

        var sprite1 = GetComponent<SpriteRenderer>();
        var sprite2 = spriteObj.GetComponent<SpriteRenderer>();
        sprite1.color = new Color(1, 1, 1, 0);
        sprite2.color = new Color(1, 1, 1, 0);
        sprite1.DOFade(1, 0.4f);
        sprite2.DOFade(1, 0.4f);
        spriteObj.transform.DOMove(spriteObj.transform.position + new Vector3(0, -5f, 0), 0.35f).SetEase(Ease.OutCubic);

        yield return new WaitForSeconds(0.35f);
        spriteObj.SetActive(false);

        for (int i = 0; i < 5; i++)
        {
            foreach (GameObject obj in targets.ToList())
            {
                if(obj.TryGetComponent(out Damageable tar))
                {
                    new Buff_Root(0.5f).Apply(owner, tar);
                    owner.ApplyDamage(tar, info, canFeedback);
                }
            }
            yield return new WaitForSeconds(0.5f);
        }
        Destroy();
    }
}
